//
//  DayButton.m
//  WOFishingBoat
//
//  Created by 郑逸凯 on 2019/1/9.
//  Copyright © 2019年 郑逸凯. All rights reserved.
//

#import "DayButton.h"

@interface DayButton ()

@property (nonatomic,strong)UIImageView *blueImageView;
@property (nonatomic,strong)UIView *dotView;

@end

@implementation DayButton


- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.blueImageView];
        [self addSubview:self.dotView];
        [self setBackgroundColor:[UIColor whiteColor]];
        self.titleLabel.font = [UIFont systemFontOfSize:14.0];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
//        self.layer.cornerRadius = 5;
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat width = self.frame.size.width;
    CGFloat height = self.frame.size.height;
    CGFloat imageWidth = width > height ? height:width;
    self.blueImageView.frame = CGRectMake((width - imageWidth)/2, 0, imageWidth, imageWidth);
    self.dotView.frame = CGRectMake((width-2)/2, height - 10, 2, 2);
}

- (void)setDayButtonType:(DayButtonType)type {
    if (type == DayButtonTypeNormal) {
        self.enabled = YES;
        [self setTitleColor:RGB16(0x999999) forState:UIControlStateNormal];
        self.blueImageView.hidden = YES;
    }else if (type == DayButtonTypeSelected) {
        self.enabled = YES;
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.blueImageView.hidden = NO;
       
    }else {
        self.enabled = NO;
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.blueImageView.hidden = YES;
    }
}

//- (void)setHasPhotos:(BOOL)has {
//    self.dotView.hidden = !has;
//    if (!has) {
//        self.photoNumber = 0;
//    }
//}

- (void)setPhotoNumber:(NSInteger)photoNumber {
    _photoNumber = photoNumber;
    self.dotView.hidden = (_photoNumber == 0);
}

- (UIView *)dotView {
    if (!_dotView) {
        _dotView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 2, 2)];
        _dotView.backgroundColor = RGB16(0x2988FC);
        _dotView.layer.masksToBounds = YES;
        _dotView.layer.cornerRadius = 1;
        _dotView.hidden = YES;
    }
    return _dotView;
}

- (UIImageView *)blueImageView {
    if (!_blueImageView) {
        _blueImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"calendar_blue_circle"]];
        _blueImageView.hidden = YES;
    }
    return _blueImageView;
}

@end
